using Moq;
using NUnit.Framework;
using OpenWaves.ImageTransformations;

namespace OpenWaves.UnitTests.ImageTransformations
{
    [TestFixture]
    public class ScaleToFillTransformationTests
    {
        [Test]
        public void ScaleToFillTransformation_survives_serialization_deserializtion_roundtrip()
        {
            var transformation = new ScaleToFillTransformation(100, 100);

            Assert.That(ImageTransformation.Parse(transformation.ToString()), Is.EqualTo(transformation));
        }

        [Test]
        public void Transformation_fills_landscape_image_into_smaller_square()
        {
            var imageMock = ImageMock.Create(400, 200);
            imageMock.Setup(i => i.Scale(200, 100)).Verifiable();
            imageMock.Setup(i => i.Crop(50, 0, 100, 100)).Verifiable();

            new ScaleToFillTransformation(100, 100).ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }

        [Test]
        public void Transformation_fills_portrait_image_into_smaller_square()
        {
            var imageMock = ImageMock.Create(200, 400);
            imageMock.Setup(i => i.Scale(100, 200)).Verifiable();
            imageMock.Setup(i => i.Crop(0, 50, 100, 100)).Verifiable();

            new ScaleToFillTransformation(100, 100).ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }

        [Test]
        public void Transformation_fills_landscape_image_into_larger_square()
        {
            var imageMock = ImageMock.Create(50, 25);
            imageMock.Setup(i => i.Scale(200, 100)).Verifiable();
            imageMock.Setup(i => i.Crop(50, 0, 100, 100)).Verifiable();

            new ScaleToFillTransformation(100, 100).ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }

        [Test]
        public void Transformation_fills_portrait_image_into_larger_square()
        {
            var imageMock = ImageMock.Create(25, 50);
            imageMock.Setup(i => i.Scale(100, 200)).Verifiable();
            imageMock.Setup(i => i.Crop(0, 50, 100, 100)).Verifiable();

            new ScaleToFillTransformation(100, 100).ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }
    }
}